import java.util.ArrayList;
import java.util.function.Predicate;

//通过Predicate接口的拼装将符合要求的字符串筛选到集合 ArrayList中，并遍历ArrayList中，并遍历ArrayList集合
//筛选要求： 同时满足以下要求：
//         1.姓名长度大于4
//         2.年龄大于 33

public class PredicateDemo2 {
    public static void main(String[] args) {
        String [] strArray = {"Jack,26","Mary,24","May,34","Linda,35","Ahn,28"};
        ArrayList<String> arrayList = myFilter(strArray, s -> s.split(",")[0].length() > 4,
                s -> Integer.parseInt(s.split(",")[1]) > 33);
        for(String str : arrayList)
            System.out.println("name : " + str.split(",")[0] + " , " + " age : " + str.split(",")[1]);
    }
    private static ArrayList<String> myFilter(String[] strArray, Predicate<String> pre1,Predicate<String> pre2){
        ArrayList<String> res = new ArrayList<>();
        for(String str : strArray)
            if(pre1.and(pre2).test(str))
                res.add(str);
        return res;
    }
}
